package com.gzx.plugin.tjzy.xxljob;

import com.gzx.plugin.tjzy.modular.call.predict.service.GzxPredictCallXxlService;
import com.gzx.plugin.tjzy.modular.call.receipt.service.GzxHtCallReceiptBusinessService;
import com.gzx.plugin.tjzy.modular.call.vos.service.GzxVosAccessGatewayService;
import com.gzx.plugin.tjzy.modular.phone.complaint.service.GzxComplaintPhoneService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import vip.xiaonuo.common.annotation.CommonCheckInstanceOnline;
import vip.xiaonuo.common.tenant.TenantContext;
import vip.xiaonuo.common.util.CommonDateUtil;

/**
 * @author zjt
 * @description
 * @date 2025/3/31 16:26
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class CallXxlJob {

    private final GzxPredictCallXxlService predictCallXxlService;

    private final GzxHtCallReceiptBusinessService htCallReceiptBusinessService;

    private final GzxVosAccessGatewayService vosAccessGatewayService;

    private final GzxComplaintPhoneService complaintPhoneService;

    /**
     * 修改预测外呼主表完成数量和状态
     */
    @XxlJob("modifyBatchStatusAndCountJobHandler")
    @CommonCheckInstanceOnline
    public void modifyBatchStatusAndCountJobHandler() {
        log.info("XxlJob定时任务启动-------修改预测外呼主表完成数量和状态-------->{}", CommonDateUtil.getCurrentTimeStr());
        TenantContext.ignoreHandle(() -> predictCallXxlService.modifyBatchStatusAndCount(XxlJobHelper.getJobParam()));
    }

    /**
     * 生成作业记录
     */
    @XxlJob("generateWorkRecordJobHandler")
    @CommonCheckInstanceOnline
    public void generateWorkRecordJobHandler() {
        log.info("XxlJob定时任务启动------生成作业记录--------->{}", CommonDateUtil.getCurrentTimeStr());
        TenantContext.ignoreHandle(htCallReceiptBusinessService::generateWorkRecord);
    }

    /**
     * 获取当前线路的并发数
     */
//    @XxlJob("getCurrentCallSizeJobHandler")
//    @CommonCheckInstanceOnline
    public void getCurrentCallSizeJobHandler() {
        vosAccessGatewayService.getCurrentCallSizeXxlJob();
    }

    /**
     * 预测外呼任务完结
     */
    @XxlJob("finishCallTaskJobHandler")
//    @CommonCheckInstanceOnline
    public void finishCallTaskJobHandler() {
        log.info("XxlJob定时任务启动-------预测外呼任务完结-------->{}", CommonDateUtil.getCurrentTimeStr());
        TenantContext.ignoreHandle(predictCallXxlService::finishCallTask);
    }

    /**
     * 预测外呼数据校验
     */
    @XxlJob("callDataVerifyJobHandler")
//    @CommonCheckInstanceOnline
    public void callDataVerifyJobHandler() {
        log.info("XxlJob定时任务启动-------预测外呼数据校验-------->{}", CommonDateUtil.getCurrentTimeStr());
        TenantContext.ignoreHandle(predictCallXxlService::verifyData);
    }

    /**
     * 投诉用户余额告警
     */
    @XxlJob("balanceWarnJobHandler")
//    @CommonCheckInstanceOnline
    public void balanceWarnJobHandler() {
        log.info("XxlJob定时任务启动-------投诉用户余额告警-------->{}", CommonDateUtil.getCurrentTimeStr());
        TenantContext.ignoreHandle(complaintPhoneService::balanceWarn);
    }
}
